/*
 * @Descripttion: 本地存储工具类
 * @version: 1.0
 * @Author: Indolphin
 * @Date: 2021-03-13 01:09:37
 * @LastEditors: Indolphin
 * @LastEditTime: 2021-03-14 14:50:18
 */

import store from 'store';
import { User } from '../interface';

export default {

    /**
     * 保存用户
     * @param {User} user
     * @return {*}
     */
    saveUserInfo(user: User) {
        store.set("user", user);
    },

    /**
     * 获取用户信息
     * 
     * @returns 用户信息
     */
    getUserInfo(): User {
        const user = store.get("user");
        if(user == null) {
            return {
                username: ''
            }
        } else {
            return user;
        }
    },

    /**
     * 保存用户token
     * 
     * @param {string} token
     * @return {*}
     */
    saveAccessToken(token: string) {
        store.set('token', token);
    },

    /**
     * 获取用户token
     * 
     * @param {*}
     * @return {*}
     */
    getAccessToken() {
        return store.get('token');
    }
};